<?php
/**
 * Created by PhpStorm.
 * User: yangfan
 * Date: 2019/11/23
 * Time: 5:39 PM
 */

namespace App\Entities;

class TransactionRecordEntity extends ABaseEntity
{
    public function __construct(TransactionRecordModel $model)
    {
        $this->model = $model;
    }

    /**
     * @param int $id
     * @return TransactionRecordEntity|null
     */
    public static function findByDistributorStateId(int $id)
    {
        $model = TransactionRecordModel::where('distributor_state_id', $id)->first();
        if (is_null($model)) {
            return null;
        }
        return new self($model);
    }

    /**
     * @param string $orderId
     * @return array
     */
    public static function getByOrderId(string $orderId)
    {
        $collection = DistributorStatModel::where('order_id', $orderId)->get();
        if ($collection->isEmpty()) {
            return [];
        }

        $ret = [];
        foreach ($collection as $model) {
            $transactionRecordEntity = self::findByDistributorStateId($model->id);
            if (!is_null($transactionRecordEntity)) {
                $ret[] = $transactionRecordEntity;
            }
        }
        return $ret;
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->model->id;
    }

    /**
     * @return int
     */
    public function getUserId()
    {
        return $this->getDisId();
    }

    /**
     * @return int
     */
    public function getDisId()
    {
        return $this->model->dis_id;
    }

    /**
     * @param int $disId
     */
    public function setDisId(int $disId)
    {
        $this->model->dis_id = $disId;
    }

    /**
     * @return int
     */
    public function getType()
    {
        return $this->model->type;
    }

    /**
     * @param int $type
     */
    public function setType(int $type)
    {
        $this->model->type = $type;
    }

    /**
     * @return string
     */
    public function getMoney()
    {
        return $this->model->money;
    }

    /**
     * @param $money
     * @return mixed
     */
    public function setMoney($money)
    {
        $this->model->money = $money;
    }

    /**
     * @return string
     */
    public function getCreatedAt()
    {
        return $this->model->created_at;
    }

    /**
     * @param string $createdAt
     */
    public function setCreatedAt(string $createdAt)
    {
        $this->model->created_at = $createdAt;
    }

    /**
     * @param int $distributor_state_id
     */
    public function setDistributorStateId(int $distributor_state_id): void
    {
        $this->model->distributor_state_id = $distributor_state_id;
    }

    /**
     * @return int
     */
    public function getDistributorStateId(): int
    {
        return $this->model->distributor_state_id;
    }

    /**
     * @param int $is_freeze
     */
    public function setIsFreeze(int $is_freeze): void
    {
        $this->model->is_freeze = $is_freeze;
    }

    /**
     * @return int
     */
    public function getIsFreeze(): int
    {
        return $this->model->is_freeze;
    }
}
